//
//  JuFunc.swift
//  JuSwift
//
//  Created by Juvid on 2017/6/30.
//  Copyright © 2017年 Juvid. All rights reserved.
//

import UIKit

//1、一般数据类型作为形参；2、函数作为形参；3、函数作为返回值
class JuFunc: NSObject {

    var optionalString: NSString?
    var emptyString = "" //
    var anotherEmptyString = String() //
    lazy var testDic: NSDictionary = {
        return NSDictionary.init()
    }()
    var juDic: NSDictionary {
        set{
            
        }get{
            return NSDictionary.init()
        }
    }
    func Jutest (){
        self.optionalString = "1234"
        let increment = makeIncrementer(sum: 12)

        let result = increment(7)
        let mulit = juBackMulit(scores: [4,6,7,9,])
        print("\(mulit.min),"+"\(mulit.max),"+"\(mulit.sum)")
        let aaa = juFuncParameter(list: [10,30,40,13,12], condition: lessThanTen)
        let bbb = lessThanTen(number: 5)
        print("\(result),"+"\(aaa),"+"\(bbb)")

    }
//    多个返回值
    func juBackMulit (scores :[Int]) -> (min:Int ,max:Int, sum:Int){
        var mins = scores[0]
        var maxs = scores[1]
        var sums = 0
        for score in scores{
            if score > maxs {
                maxs=score;
            }else if score < mins{
                mins=score
            }
            sums+=score;
        }
        return (mins,maxs,sums)
    }

    /// block/函数作为返回值
    func makeIncrementer(sum:Int) -> ((Int) -> Int) {
//        函数
        if sum < 13 {
            func addOne(number: Int) -> Int {
                return 1 + number + sum
            }
    //        addOne(number: 15)
            return addOne
        }
//block
        return {nunber in
            return nunber + sum
        }
    }
    
    func juBackFunc(sum:Int) -> Int {
          func addOne(number: Int) -> Int {
              return 1 + number + sum
          }
          return addOne(number: 15)
      }

    ///increment变量是个函数addOne
    func juFuncParameter (list:[Int] ,condition: (Int)/*传入函数的参数类型*/ -> Bool/*传入返回值类型*/) ->Bool{
        for item in list{
            if condition(item) {
                NSLog("对")
                return true
            }
        }
        NSLog("错")
        return false
    }

    func lessThanTen (number :Int) -> Bool{
        return number < 10
    }
//    var numberss = [10,30,40,13,12]

    
    public final func greet (name:String ,day:String) ->String{
        return "hello \(name),today is \(day)"
    }

}
